/**************************************************************************************************
  Filename:       simpleBLECentral.h
  Revised:        $Date: 2011-03-03 15:46:41 -0800 (Thu, 03 Mar 2011) $
  Revision:       $Revision: 12 $

  Description:    This file contains the Simple BLE Central sample application
                  definitions and prototypes.
**************************************************************************************************/

#ifndef CENT_H
#define CENT_H

#ifdef __cplusplus
extern "C"
{
#endif

/*********************************************************************
 * INCLUDES
 */
#include "bcomdef.h"
#include "OSAL.h"
#include "OSAL_PwrMgr.h"
#include "OnBoard.h"

#include "hal_drivers.h"
#include "hal_uart.h"
#include "gatt.h"
#include "ll.h"
#include "hci.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "central.h"
#include "gapbondmgr.h"
#include "dataservice.h"
#include "gatt_uuid.h"
#include "gatt_profile_uuid.h"
#include "battprofile.h" 
/*********************************************************************
 * CONSTANTS
 */

enum
{
  DISC_IDLE = 0x00,                       // Idle state
  
  DISC_DATA_START = 0x10,            	   // Current time service
  DISC_DATA_SVC,                     	   // Discover service
  DISC_DATA_CHAR,                    	   // Discover all characteristics
  DISC_DATA_PACK_CCCD,					   // Discover CT time CCCD
 
  DISC_BATT_START = 0x20,                 // Battery service
  DISC_BATT_SVC,                          // Discover service
  DISC_BATT_CHAR,                         // Discover all characteristics
  DISC_BATT_LVL_CCCD,                     // Discover battery level CCCD

  DISC_FAILED = 0xFF                      // Discovery failed
};

// Bebe App handle cache indexes
enum
{
  HDL_DATA_PACK_START,            	// Data start handle
  HDL_DATA_PACK_END,              	// Data end handle
  HDL_DATA_PACK_CCCD,          	// Data pack CCCD
  HDL_DATA_ACK,                 // Data ack point
  HDL_DATA_CTRL,               	// Data control point
  
  HDL_BATT_LEVEL_START,                   // Battery level start handle
  HDL_BATT_LEVEL_END,                     // Battery level end handle
  HDL_BATT_LEVEL_CCCD,                    // Battery level CCCD

  HDL_CACHE_LEN
};
// Configuration states
#define CENT_CONFIG_START              0x00
#define CENT_CONFIG_CMPL               0xFF
// Index into timeAppConfigList to start of connection setup characteristics
#define CENT_CONFIG_CONN_START         4

// Simple BLE Central Task Events
#define START_DEVICE_EVT                              0x0001
#define START_DISCOVERY_EVT                           0x0002

#define DISPLAY_DISC_RESULT_EVT					      0x0010
#define PROC_DISC_EVT							 	  0x0020
#define CONNECTION_UPDATE_EVT 						  0x0040
#define TERMINATE_CONNECTION_EVT					  0x0080
#define TOGGLE_RSSI_POLLING_EVT   					  0x0100
#define ESTABLIST_LINK_EVT							  0x0200
/*********************************************************************
 * MACROS
 */


 // Task ID for internal task/event processing
extern uint8 centBLETaskId;

// Connection handle
extern uint16 centConnHandle;

// Handle cache
extern uint16 centHdlCache[HDL_CACHE_LEN];

// LCD macros 
 /*
    Comment by Liber
 */
// #if HAL_LCD == TRUE
// #define LCD_WRITE_STRING(str, option)                       HalLcdWriteString( (str), (option))
// #define LCD_WRITE_SCREEN(line1, line2)                      HalLcdWriteScreen( (line1), (line2) )
// #define LCD_WRITE_STRING_VALUE(title, value, format, line)  HalLcdWriteStringValue( (title), (value), (format), (line) )
// #else
// #define LCD_WRITE_STRING(str, option)                     
// #define LCD_WRITE_SCREEN(line1, line2)                    
// #define LCD_WRITE_STRING_VALUE(title, value, format, line)
// #endif

/*********************************************************************
 * FUNCTIONS
 */

/*
 * Task Initialization for the BLE Application
 */
extern void Cent_Init( uint8 task_id );

/*
 * Task Event Processor for the BLE Application
 */
extern uint16 Cent_ProcessEvent( uint8 task_id, uint16 events );


//Discovery
extern uint8 centDiscStart( void );
extern uint8 centDiscGattMsg( uint8 state, gattMsgEvent_t *pMsg );

//Stream
extern uint8 centConfigNext( uint8 state );
extern uint8 centConfigGattMsg( uint8 state, gattMsgEvent_t *pMsg );
extern void centNotiGattMsg( gattMsgEvent_t *pMsg );
/*********************************************************************
*********************************************************************/

#ifdef __cplusplus
}
#endif

#endif /* SIMPLEBLECENTRAL_H */
